package com.frxuexi.park2212.patrol

import androidx.databinding.DataBindingUtil
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.frxuexi.lib_base.entity.PatrolTaskBeanItem
import com.frxuexi.park2212.R
import com.frxuexi.park2212.databinding.ItemTaskBinding

class TaskAdapter:BaseQuickAdapter<PatrolTaskBeanItem,BaseViewHolder>(R.layout.item_task) {
    lateinit var binding:ItemTaskBinding
    override fun onItemViewHolderCreated(viewHolder: BaseViewHolder, viewType: Int) {
        super.onItemViewHolderCreated(viewHolder, viewType)
        DataBindingUtil.bind<ItemTaskBinding>(viewHolder.itemView)
    }
    override fun convert(helper: BaseViewHolder, item: PatrolTaskBeanItem) {
        binding=DataBindingUtil.getBinding<ItemTaskBinding>(helper.itemView)!!
        binding.bean=item

        when(item.patrolStatus){
            "0"->
                binding.taskType.apply {
                    setText("未巡检")
                    setBackgroundResource(R.drawable.shape_zhanyong)
                    setTextColor(context.getColor(R.color.blue))
                }
            "1"->
                binding.taskType.apply {
                    setText("巡检中")
                    setBackgroundResource(R.drawable.shape_weihu)
                    setTextColor(context.getColor(R.color.orange))
                }
            "2"->
                binding.taskType.apply {
                    setText("已完成")
                    setBackgroundResource(R.drawable.shape_status)
                    setTextColor(context.getColor(R.color.green))
                }
            else->{
                binding.taskType.apply {
                    setText("已作废")
                    setBackgroundResource(R.drawable.shape_solid_lightgray)
                    setTextColor(context.getColor(R.color.darkgray))
                }
            }
        }
    }
}